package com.fg.pro.trade.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fg.pro.trade.dao.TradeOrderDetailDao;
import com.fg.pro.trade.entity.TradeOrder;
import com.fg.pro.trade.entity.TradeOrderDetail;
import com.fg.pro.trade.service.TradeOrderDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 订单详情(TradeOrderDetail)表服务实现类
 *
 * @author makejava
 * @since 2025-08-17 10:01:50
 */
@Service("tradeOrderDetailService")
public class TradeOrderDetailServiceImpl extends ServiceImpl<TradeOrderDetailDao, TradeOrderDetail> implements TradeOrderDetailService {

    @Override
    public PageInfo getPage(Integer pageNum, Integer pageSize, Date start, Date end, String goodsName, String orderCode) {
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PageHelper.startPage(pageNum, pageSize);
        List<TradeOrderDetail> list = query()
                .ge("receive_time",sdfs.format(DateUtil.beginOfDay(start)))
                .le("receive_time",sdfs.format(DateUtil.endOfDay(end)))
                .like(StrUtil.isNotBlank(goodsName),"order_detail_sku_name", goodsName)
                .like(StrUtil.isNotBlank(orderCode),"order_detail_serial_no",orderCode)
                .orderByDesc("receive_time")
                .list();
        PageInfo<TradeOrderDetail> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}

